//
//  YKButton.m
//  ykView
//
//  Created by HuangSui on 2017/8/3.
//  Copyright © 2017年 Demo. All rights reserved.
//

#import "YKButton.h"
@implementation YKButton


-(void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
{
    [super setBackgroundImage:image forState:state];
    if (self.type) {
        
    
    if ([UIImagePNGRepresentation(image) isEqual:UIImagePNGRepresentation([UIImage imageNamed:@"添加图片"])]){
        
    
        
        if (self.delButton) {
            self.delButton.hidden=YES;
        }
        
    }else
    {
        if (self.delButton) {
            self.delButton.hidden=NO;
        }else
        {
            self.delButton=[UIButton buttonWithType:UIButtonTypeCustom];
            [self.superview addSubview:self.delButton];
            [self.delButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(self).mas_offset(9);
                make.top.mas_equalTo(self).mas_offset(-9);
            }];
            [self.delButton setImage:[UIImage imageNamed:@"消除"] forState:UIControlStateNormal];
            [self.delButton addTarget:self action:@selector(clearImage) forControlEvents:UIControlEventTouchUpInside];
            
        }
    }
    }
}
-(void)clearImage
{
    [self setBackgroundImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
}
@end
